package day20171221;

import java.io.*;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Test {

        public static void main(String[] args) {
            Map<String, Integer> map = new HashMap<>();
            String stuNO = "";

            //字符流方式读文件
            String path = "D:\\names.txt";
            BufferedReader reader = null;
            try {
                reader = new BufferedReader(new FileReader(path));
                try {
                    while ((stuNO = reader.readLine()) != null) {
                        map.put(stuNO, 0);

                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } finally {
                try {
                    reader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            File file = new File("D:\\16信本2班Java作业一");
            File[] files = file.listFiles();
            //遍历
            for (File f : files) {
                String filename = f.getName();
                //保存到提取学号
                String no = "";
                //从文件名中提取学号
                //正则表达式:1.模板；2.三个填空
                Matcher matcher = Pattern.compile("信本2班(\\d+)").matcher(filename);
                while (matcher.find()) {
                    no = matcher.group(1);
                    System.out.println(map);
                }
                map.put(no, 1);
            }
            //把value为0的打印出来
            //遍历一个map
            for (Map.Entry<String, Integer> entry : map.entrySet()) {
                if (entry.getValue() == 0) {
                    System.out.println(entry.getKey());
                }
            }
        }
    }

